{% extends 'homepage.html' %}
{% block content %}

<script>
{% if N %}
var N = {{N}};
{% else %}
var N = 0;
{% endif %}

{% if t %}
var t = {{t}};
{% else %}
var t = 0;
{% endif %}

{% if limit %}
var limit = {{limit}};
{% else %}
var limit = 100;
{% endif %}
var tstr = "";
if(t > 0) {
    tstr = String(t);
}
var Nstr = "";
if(N > 0) {
    Nstr = String(N);
}
var argstring = '?N='+Nstr+"&t="+tstr+"&limit="+limit;
listzeros_url = '{{url_for(".list_zeros")}}';
displayzeros_url = '{{url_for(".zetazeros")}}';
function loadzeros(save_history) {
    var request = new XMLHttpRequest();
    request.onreadystatechange = function() {
        if(request.readyState == 4 && request.status == 200) {
            var zero_table = document.getElementById('zero_table');
            var old_length = zero_table.rows.length
            for(var n = 0; n < old_length - 1; n++) {
                zero_table.deleteRow(-1);
            }
            var lines = request.responseText.split('\n');
            N = Number(lines[0].split(' ')[0]);
            t = Number(lines[0].split(' ')[1]);
            document.getElementById("Nbox").value = N;
            document.getElementById("tbox").value = t;
            for(var n = 0; n < lines.length; n++) {
                if(lines[n] == "") {
                    continue;
                }
                var entry = lines[n].split(' ');
                var row = zero_table.insertRow(-1);
                var cell = row.insertCell(-1);
                cell.appendChild(document.createTextNode(entry[0]));
                cell = row.insertCell(-1);
                cell.appendChild(document.createTextNode(entry[1]));
            }
        }
    };
    tstr = "";
    if(t > 0) {
        tstr = String(t);
    }
    Nstr = "";
    if(N > 0) {
        Nstr = String(N);
    }
    argstring = '?N='+Nstr+"&t="+tstr+"&limit="+limit;
    if(save_history) {
        history.pushState({'N' : N, 't' : t, 'limit' : limit}, "zeta zeros", displayzeros_url + argstring);
    }
    document.getElementById('plainlink').href = listzeros_url + argstring;
    document.getElementById('plaindownloadlink').href = listzeros_url + argstring + '&download=yes';

    request.open('GET', listzeros_url + argstring, true);
    request.send(null);
};
function next() {
    N = N + limit;
    t = 0;
    loadzeros(true);
};
function prev() {
    N = N - limit;
    t = 0;
    loadzeros(true);
};
var oldonload = window.onload;
window.onload = function() {
    if(oldonload) {
        oldonload();
    }
    loadzeros(false);
};
window.onpopstate = function(event) {
    if(event.state) {
        N = event.state.N;
        t = event.state.t;
        limit = event.state.limit;
        loadzeros(false);
    }
};
</script>
<form align="center">
List <input type="text" name="limit" value="{{limit}}" style="width:5em"/> zeros of the zeta function starting with
zero number <input type="text" value="{{N}}" name="N" id="Nbox"/> <button type="submit" value="Go">Go</button>
</form>
<form align="center">
List <input type="text" name="limit" value="{{limit}}" style="width:5em"/> zeros of the zeta function staring with imaginary part 
<input type="text" value="{{t}}" name="t" id="tbox" /> <button type="submit" value="Go">Go</button>
</form>
<br/>
<div align="center">
<a id="plainlink" href="">View</a> or <a id="plaindownloadlink" href="">download</a> this table as plain text.
</div>
<br/>
<div align="center">
{{KNOWL('zeros.zeta.contents', title="Contents of these tables.")}}
</div>
<br/>
<div align="center">
<a href="#" class="navlink" onclick="prev(); return false">Previous {{limit}}</a>
<a href="#" class="navlink" onclick="next(); return false">Next {{limit}}</a>
</div>
<table class='ntdata' id='zero_table' align="center">
<thead><td>Zero number</td><td>Imaginary part</td></thead>
</table>

{% endblock %}
